import origonAxios from "axios";

export default function axios(option) {
    return new Promise((resolve, reject) => {
        // 1.创建 axios 示例
        const instance = origonAxios.create({
            baseURL: process.env.VUE_APP_APP_BASEURL
        })

        //配置请求拦截
        instance.interceptors.request.use(config => {
            config.headers['userId'] = localStorage.getItem('banma-user')
            return config
        }, err => {
            return err
        })

        //配置响应拦截
        instance.interceptors.response.use(response => {
            return response.data
        }, err => {
            return err
        })

        // 2.传入对象进行网络请求
        instance(option)
            .then(res => {
                resolve(res)
            })
            .catch( err => {
                reject(err)
            })
    })

}